// pages/shop_data/shop_data.js
const config = require('../../config.js');
const utils = require('../../utils/util.js');
const request = require('../../utils/request.js')
import {
    getStoreDataList
} from '../../static/api/api.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        starDate: '',
        endDate: '',
        curItem:null,
        listData: null,
        curService:null,
        curFinace:null,
        serviceType: [{
            name: '全部',
            id: ''
        }, {
            name: '上门',
            id: '10'
        }, {
            name: '到店',
            id: '20'
        }],
        finaceType: [{
            name: '全部',
            id: ''
        }, {
            name: '提现',
            id: '64'
        }, {
            name: '未提现',
            id: '60'
        }],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getStoreDataList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    getStoreDataList(e) {
        let that = this;
        wx.showLoading({
            title: '加载中...',
        })
        let options = {
            start_time: this.data.starDate,
            end_time: this.data.endDate,
            size: 999,
            order_type: this.data.curService ? this.data.curService.id : '',
            status: this.data.curFinace ? this.data.curFinace.id : ''
        }
        getStoreDataList(options).then(response => {
            wx.hideLoading();
            console.log(response.data)
            that.setData({
                'listData': response.data,
                'orderStatus': utils.orderStatus
            })
        }).catch(response => {
            wx.hideLoading();
        })
    },
    bindStarDateChange(e) {
        console.log(e);
        this.setData({
            starDate: e.detail.value
        })
    },
    bindEndDateChange(e) {
        console.log(e);
        this.setData({
            endDate: e.detail.value
        })
    },
    showServiceType() {
        let itemArr = [];
        let that = this;
        this.data.serviceType.forEach((el, index) => {
            itemArr[index] = el.name;
        })
        wx.showActionSheet({
            itemList: itemArr,
            success: function(res) {
                console.log(res.tapIndex)
                that.setData({
                    'curService': that.data.serviceType[res.tapIndex]
                })
            },
            fail: function(res) {
                console.log(res.errMsg)
            }
        })
    },
    showFinaceType() {
        let itemArr = [];
        let that = this;
        this.data.finaceType.forEach((el, index) => {
            itemArr[index] = el.name;
        })
        wx.showActionSheet({
            itemList: itemArr,
            success: function (res) {
                console.log(res.tapIndex)
                that.setData({
                    'curFinace': that.data.finaceType[res.tapIndex]
                })
            },
            fail: function (res) {
                console.log(res.errMsg)
            }
        })
    },
    showOrderDetail(e){
        let dataset = e.currentTarget.dataset;
        this.setData({
            'curItem':dataset.item,
            'isOrderStepShow':true
        })
    },
    _hideDialog(){
        this.setData({
            'isOrderStepShow': false
        }) 
    }
})